package com.fengze.business.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fengze.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fengze.common.annotation.Log;
import com.fengze.common.core.controller.BaseController;
import com.fengze.common.core.domain.AjaxResult;
import com.fengze.common.enums.BusinessType;
import com.fengze.business.domain.ProjectPlan;
import com.fengze.business.service.IProjectPlanService;
import com.fengze.common.utils.poi.ExcelUtil;
import com.fengze.common.core.page.TableDataInfo;

/**
 * 项目计划Controller
 * 
 * @author lug
 * @date 2024-02-02
 */
@RestController
@RequestMapping("/project/plan")
public class ProjectPlanController extends BaseController
{
    @Autowired
    private IProjectPlanService projectPlanService;

    /**
     * 查询项目计划列表
     */
    @PreAuthorize("@ss.hasPermi('project:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectPlan projectPlan)
    {
        startPage();
        List<ProjectPlan> list = projectPlanService.selectProjectPlanList(projectPlan);
        return getDataTable(list);
    }

    /**
     * 导出项目计划列表
     */
    @PreAuthorize("@ss.hasPermi('project:plan:export')")
    @Log(title = "项目计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectPlan projectPlan)
    {
        List<ProjectPlan> list = projectPlanService.selectProjectPlanList(projectPlan);
        ExcelUtil<ProjectPlan> util = new ExcelUtil<ProjectPlan>(ProjectPlan.class);
        util.exportExcel(response, list, "项目计划数据");
    }

    /**
     * 获取项目计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectPlanService.selectProjectPlanById(id));
    }

    /**
     * 新增项目计划
     */
    @PreAuthorize("@ss.hasPermi('project:plan:add')")
    @Log(title = "项目计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectPlan projectPlan)
    {
        return toAjax(projectPlanService.insertProjectPlan(projectPlan));
    }

    /**
     * 修改项目计划
     */
    @PreAuthorize("@ss.hasPermi('project:plan:edit')")
    @Log(title = "项目计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectPlan projectPlan)
    {
        return toAjax(projectPlanService.updateProjectPlan(projectPlan));
    }

    /**
     * 删除项目计划
     */
    @PreAuthorize("@ss.hasPermi('project:plan:remove')")
    @Log(title = "项目计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectPlanService.deleteProjectPlanByIds(ids));
    }

    @Anonymous
    @RequestMapping("/test")
    public Object test(){
        List<ProjectPlan> list = new ArrayList<>();
        ProjectPlan projectPlan = new ProjectPlan();
        projectPlan.setStartTime(new Date());
        projectPlan.setEndTime(new Date());
        projectPlan.setPlanContent("计划内容");
        projectPlan.setStatus(1);
        projectPlan.setCompletionStatus("完成20%");
        list.add(projectPlan);

        String str = "[{\"completionStatus\":\"完成20%\",\"endTime\":\"2024-02-05\",\"params\":{},\"planContent\":\"计划内容\",\"startTime\":\"2024-02-05\",\"status\":1}]";
        String str1 = "[{\"completionStatus\":\"完成20%\",\"endTime\":\"2024-02-05\",\"params\":{},\"planContent\":\"计划内容\",\"startTime\":\"2024-02-05\",\"status\":1}]";
        return JSON.toJSONString(list);
    }
}
